import { ref, watch } from "vue";
import { BIndType, Cardmin } from "../../card/script/card"
import { URL_FOLLOW_TWITTER, URL_LOGIN_TWITTER, URL_TWITTER_CALLBACK } from "@/comm/api";
import { get, post } from "@/comm/request";
import { toast } from "@/components/toast/toast";
import { useAccount } from "@/stores/account";
const account = useAccount()
watch(() => account.joinToken, async val => {
    console.log(account.joinToken)
    window.open('https://twitter.com/intent/user?screen_name=ChainingView', '_blank');
         let url = URL_FOLLOW_TWITTER.replace("@", val.id);
        const reward: any = await get(url)
        console.log(reward)
        if (reward.code == 200) {
            console.log("领取推特关注奖励");
        }

    // if (!val.bound) {
    //     window.open('https://twitter.com/intent/user?screen_name=ChainingView', '_blank');
    // } else {
    //     let url = URL_FOLLOW_TWITTER.replace("@", '1');
    //     const reward: any = await post(url)
    //     console.log(reward)
    //     if (reward.code == 200) {
    //         console.log("领取推特关注奖励");
    //     }
    // }
});
const fans_alert = {
    show: ref(false),
    bindType: ref(''),
    open() {
        this.show.value = true;
    },
    close() {
        this.show.value = false;
    },
    changeType(type: string) {
        this.bindType.value = type
    },
    async bind() {
        if (this.bindType.value == BIndType.TWITTER) {
            const res: any = await post(URL_TWITTER_CALLBACK, { type: 3 }, true)
            if (res.data.bound) {
                let url = URL_FOLLOW_TWITTER.replace("@", '1');
                const reward: any = await post(url)
                console.log(reward)
                if (res.code == 200) {
                    console.log("领取推特关注奖励");
                }
            }
        } else {
            console.log("TG没弄");
        }
    },
    goBind() {

    },
}

export { fans_alert };